//
//  GHDIscoverController.m
//  12-guhu_weibo
//
//  Created by GHapple on 15-1-31.
//  Copyright (c) 2015年 itcast. All rights reserved.
//

#import "GHDIscoverController.h"
#import "GHsearchTf.h"

@interface GHDIscoverController ()<UITextFieldDelegate>

@property(nonatomic,weak)GHsearchTf *searchTf;

@end

@implementation GHDIscoverController

- (void)viewDidLoad {
    [super viewDidLoad];
    
//    UISearchBar *searchBar = [[UISearchBar alloc]init];
//    self.navigationItem.titleView = searchBar;
//     自动以searchbar
 /*   UITextField *searchTf = [[UITextField alloc]init];
    self.navigationItem.titleView = searchTf;
    searchTf.frame = CGRectMake(0, 0, 300, 30);  //  titleView 设置X和Y是无效的
    // UITextField要设置边框的样式(默认没有边框)
    searchTf.borderStyle = UITextBorderStyleRoundedRect;
    searchTf.placeholder = @"请输入你想搜索的内容";
    searchTf.clearButtonMode = UITextFieldViewModeAlways;
    
    // 添加放大镜  通过UIImageView的initWithImage创建出来的可以不设置frame默认是image的宽高
    
    UIImageView *icon = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"searchbar_searchlist_search_icon"]];
    [searchTf addSubview:icon];
    searchTf.leftView = icon;
    // 设置leftView的样式
    searchTf.leftViewMode = UITextFieldViewModeAlways;
    // 监听文本框的输入*/
    GHsearchTf *searchTf = [[GHsearchTf alloc]init];
    searchTf.frame = CGRectMake(0, 0, 300, 30);
    
    self.navigationItem.titleView  = searchTf;
    searchTf.delegate = self;
    self.searchTf = searchTf;
    
    self.defaultView.turnIcon.hidden = NO;
    
   }


- (void)viewWillAppear:(BOOL)animated{
    
    [self.defaultView startTurn];
}

- (void)viewWillDisappear:(BOOL)animated{
    [self.defaultView stopTurn];
}
#pragma mark  文本框输入的代理方法
- (void)textFieldDidBeginEditing:(UITextField *)textField{
// 开始编辑的时候添加取消按钮
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"取消" style:UIBarButtonItemStylePlain target:self action:@selector(cancle)];
    self.searchTf.iconName = @"settings_statistic_triangle";
    
    
    
    // 将放大镜按钮换为像下的尖头
//   UIImageView *icon = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"settings_statistic_triangle"]];
//    icon.contentMode = UIViewContentModeCenter;
//    icon.width = 30;
    //    self.searchTf.leftView = icon;
    
//    self.searchTf.iconName = @"settings_statistic_triangle";

}


- (void)cancle{
    // 影藏取消按钮
    self.navigationItem.rightBarButtonItem = nil;
    // 退出键盘
    [[UIApplication sharedApplication].keyWindow endEditing:YES];
    // 还原放大镜
    self.searchTf.leftView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"searchbar_searchlist_search_icon"]];
    
}
#pragma mark 监听滚动


- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{

    // 退出键盘
    [[UIApplication sharedApplication].keyWindow endEditing:YES];
}




@end
